// 这个方法导致需要多判断很多次
var lengthOfLongestSubstring = function(s) {
     const map = new Map()
     let left = 0, right = 0
     let ans = 0
     while (right < s.length) {
        if(map.get(s[right]) !== undefined) { // 收缩窗口
            let inx = map.get(s[right])
            while(left <= inx) {
                map.set(s[left], undefined)
                left++
            }
        }
        map.set(s[right], right)
        ans = Math.max(ans, right - left + 1)
        right++
     }
     return ans
 }
 console.log(lengthOfLongestSubstring("abc"));